package com.sz.mes.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diboot.core.vo.JsonResult;
import com.sz.mes.entity.CastMaterial;
import com.sz.mes.entity.Output;
import com.sz.mes.entity.Technique;
import com.sz.mes.mapper.*;
import com.sz.mes.service.OutputService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* 产出相关Service实现
* @author hem
* @version 1.0
* @date 2024-01-15
 * Copyright © szhs
*/
@Service
@Slf4j
public class OutputServiceImpl extends BaseCustomServiceImpl<OutputMapper, Output> implements OutputService {
    private final TechniqueMapper techniqueMapper;
    private final OutputMapper outputMapper;

    public OutputServiceImpl(TechniqueMapper techniqueMapper, OutputMapper outputMapper) {
        this.techniqueMapper = techniqueMapper;
        this.outputMapper = outputMapper;
    }

    @Override
    public JsonResult findDetail(String taskNum) {
        QueryWrapper<Technique> tqw = new QueryWrapper<>();
        tqw.eq("task_num",taskNum);
        List<Technique> techniqueList = techniqueMapper.selectList(tqw);

        List<Output> outputList=new ArrayList<>();
        for (Technique t:techniqueList){
            QueryWrapper<Output> cqw = new QueryWrapper<>();
            cqw.eq("tech_id",t.getId());
            List<Output> list = outputMapper.selectList(cqw);
            outputList.addAll(list);
        }

        return JsonResult.OK(outputList);
    }
}
